package cn.progen.generator.web;

import cn.progen.constant.Config;
import cn.progen.generator.Generator;
import cn.progen.model.Table;
import cn.progen.util.FreemarkerUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wangYuDong on 2017/6/4.
 */
public class WebServiceGenerator extends Generator {
    @Override
    public void out(List<Table> taList) {
        taList.forEach(item->{
            FreemarkerUtil freemarkerUtil=new FreemarkerUtil(Config.Path.WEB_PATH, "services\\"+item.getClassName()+"Service.js");
            Map dataMap=new HashMap<>();
            dataMap.put("table",item);
            freemarkerUtil.createDoc(dataMap, "web/service.js.ftl");

            FreemarkerUtil freemarkerUtil1=new FreemarkerUtil(Config.Path.WEB_PATH, "models\\"+item.getClassName()+"Model.js");
            freemarkerUtil1.createDoc(dataMap, "web/model.js.ftl");

            FreemarkerUtil freemarkerUtil12=new FreemarkerUtil(Config.Path.WEB_PATH, "routes\\"+item.getClassName()+"Route.js");
            freemarkerUtil12.createDoc(dataMap, "web/route.js.ftl");
        });

        FreemarkerUtil freemarkerUtil=new FreemarkerUtil(Config.Path.WEB_PATH, "menu.js");
        Map dataMap=new HashMap<>();
        dataMap.put("tables",taList);
        freemarkerUtil.createDoc(dataMap, "web/menu.ftl");

        FreemarkerUtil freemarkerUtil2=new FreemarkerUtil(Config.Path.WEB_PATH, "router.js");
        dataMap.put("tables",taList);
        freemarkerUtil2.createDoc(dataMap, "web/index.router.js.ftl");

    }
}
